/*
 * @Description: 该文件描述
 * @FilePath: \fortune_h5\src\router\index.ts
 * @Author: Brian Brian@gmail.com
 * @Date: 2024-10-25 14:22:27
 * @LastEditors: Brian Brian@gmail.com
 * @LastEditTime: 2024-10-31 09:55:44
 */
import {
  createRouter,
  createWebHistory,
  type RouteRecordRaw,
} from "vue-router";
import Layout from "@/layout/index.vue";
import Home from "@/modules/home/views/index.vue";
import Result from "@/modules/home/views/result.vue";
// // 扫描文件
// const files = import.meta.glob(["../modules/**/{views,pages}/*.vue"]);

// const generateRoutes = (modules: string[]) => {
//   const modulesRoutes: Record<string, any> = {};
//   const subModulesRoutes: Record<string, string> = {};

//   for (let i = 0; i < modules.length; i++) {
//     const item = modules[i];
//     const [dirname, type, filename] = item
//       .replace("../modules/", "")
//       .replace(".vue", "")
//       .split("/");
//     if (filename.includes("_")) {
//       subModulesRoutes[`${type}_${dirname}_${filename}`] = item;
//       continue;
//     }
//     modulesRoutes[`${type}_${dirname}_${filename}`] = {
//       path: `${type === "views" ? "" : "/"}${dirname}${filename === "index" ? "" : "_" + filename}`,
//       component: () => import(item),
//       children: [],
//     };
//   }
//   Object.entries(subModulesRoutes).forEach(([key, value]) => {
//     const [type, dirname, parentFilename, filename] = key.split("_");
//     if (!modulesRoutes[`${type}_${dirname}_${parentFilename}`]) {
//       throw new Error(
//         `parent route ${type}/${dirname}/${parentFilename}.vue not found`
//       );
//     }
//     modulesRoutes[`${type}_${dirname}_${parentFilename}`].children.push({
//       path: `${filename}`,
//       component: () => import(value),
//     });
//   });

//   return (Object.entries(modulesRoutes) as [string, string][]).reduce<
//     Record<string, string[]>
//   >(
//     (init, [key, value]) => {
//       if (key.startsWith("views")) init.views.push(value);
//       if (key.startsWith("pages")) init.pages.push(value);
//       return init;
//     },
//     { views: [], pages: [] }
//   );
// };

// const { views, pages } = generateRoutes(Object.keys(files));
const routes = [
  {
    path: "/",
    component: Layout,
    children: [
      {
        path: "",
        component: Home,
      },
      {
        path: "/home_result",
        component: Result,
      },
    ],
  },
] as Readonly<RouteRecordRaw[]>;

const router = createRouter({
  history: createWebHistory(),
  routes,
});
export default router;
